home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue41 / ComCorn / LVImpl.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-12-03  |  15.3 KB  |  571 lines

  1. unit LVImpl;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, ActiveX, Classes, Controls, Graphics, Menus, Forms, StdCtrls,
  7.   ComServ, StdVCL, AXCtrls, LVCtrl_TLB, ListView2, ComCtrls, LVItems;
  8.  
  9. type
  10.   TListViewX = class(TActiveXControl, IListViewX)
  11.   private
  12.     { Private declarations }
  13.     FDelphiControl: TListView2;
  14.     FEvents: IListViewXEvents;
  15.     FItems: IListItems;
  16.     procedure ClickEvent(Sender: TObject);
  17.     procedure DataHintEvent(Sender: TObject; StartIndex, EndIndex: Integer);
  18.     procedure DblClickEvent(Sender: TObject);
  19.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  20.     procedure ResizeEvent(Sender: TObject);
  21.   protected
  22.     { Protected declarations }
  23.     procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  24.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  25.     procedure InitializeControl; override;
  26.     function AlphaSort: WordBool; safecall;
  27.     function ClassNameIs(const Name: WideString): WordBool; safecall;
  28.     function DrawTextBiDiModeFlags(Flags: Integer): Integer; safecall;
  29.     function DrawTextBiDiModeFlagsReadingOnly: Integer; safecall;
  30.     function Get_AllocBy: Integer; safecall;
  31.     function Get_BiDiMode: TxBiDiMode; safecall;
  32.     function Get_BorderStyle: TxBorderStyle; safecall;
  33.     function Get_Checkboxes: WordBool; safecall;
  34.     function Get_Color: OLE_COLOR; safecall;
  35.     function Get_ColumnClick: WordBool; safecall;
  36.     function Get_Ctl3D: WordBool; safecall;
  37.     function Get_Cursor: Smallint; safecall;
  38.     function Get_DoubleBuffered: WordBool; safecall;
  39.     function Get_DragCursor: Smallint; safecall;
  40.     function Get_DragMode: TxDragMode; safecall;
  41.     function Get_Enabled: WordBool; safecall;
  42.     function Get_FlatScrollBars: WordBool; safecall;
  43.     function Get_Font: IFontDisp; safecall;
  44.     function Get_FullDrag: WordBool; safecall;
  45.     function Get_GridLines: WordBool; safecall;
  46.     function Get_HideSelection: WordBool; safecall;
  47.     function Get_HotTrack: WordBool; safecall;
  48.     function Get_MultiSelect: WordBool; safecall;
  49.     function Get_OwnerData: WordBool; safecall;
  50.     function Get_OwnerDraw: WordBool; safecall;
  51.     function Get_ParentColor: WordBool; safecall;
  52.     function Get_ParentFont: WordBool; safecall;
  53.     function Get_ReadOnly: WordBool; safecall;
  54.     function Get_RowSelect: WordBool; safecall;
  55.     function Get_SelCount: Integer; safecall;
  56.     function Get_ShowColumnHeaders: WordBool; safecall;
  57.     function Get_SortType: TxSortType; safecall;
  58.     function Get_ViewStyle: TxViewStyle; safecall;
  59.     function Get_Visible: WordBool; safecall;
  60.     function Get_VisibleRowCount: Integer; safecall;
  61.     function GetControlsAlignment: TxAlignment; safecall;
  62.     function GetSearchString: WideString; safecall;
  63.     function IsEditing: WordBool; safecall;
  64.     function IsRightToLeft: WordBool; safecall;
  65.     function StringWidth(const S: WideString): Integer; safecall;
  66.     function UseRightToLeftAlignment: WordBool; safecall;
  67.     function UseRightToLeftReading: WordBool; safecall;
  68.     function UseRightToLeftScrollBar: WordBool; safecall;
  69.     procedure _Set_Font(const Value: IFontDisp); safecall;
  70.     procedure AboutBox; safecall;
  71.     procedure Arrange(Code: TxListArrangement); safecall;
  72.     procedure FlipChildren(AllLevels: WordBool); safecall;
  73.     procedure InitiateAction; safecall;
  74.     procedure Scroll(DX, DY: Integer); safecall;
  75.     procedure Set_AllocBy(Value: Integer); safecall;
  76.     procedure Set_BiDiMode(Value: TxBiDiMode); safecall;
  77.     procedure Set_BorderStyle(Value: TxBorderStyle); safecall;
  78.     procedure Set_Checkboxes(Value: WordBool); safecall;
  79.     procedure Set_Color(Value: OLE_COLOR); safecall;
  80.     procedure Set_ColumnClick(Value: WordBool); safecall;
  81.     procedure Set_Ctl3D(Value: WordBool); safecall;
  82.     procedure Set_Cursor(Value: Smallint); safecall;
  83.     procedure Set_DoubleBuffered(Value: WordBool); safecall;
  84.     procedure Set_DragCursor(Value: Smallint); safecall;
  85.     procedure Set_DragMode(Value: TxDragMode); safecall;
  86.     procedure Set_Enabled(Value: WordBool); safecall;
  87.     procedure Set_FlatScrollBars(Value: WordBool); safecall;
  88.     procedure Set_Font(var Value: IFontDisp); safecall;
  89.     procedure Set_FullDrag(Value: WordBool); safecall;
  90.     procedure Set_GridLines(Value: WordBool); safecall;
  91.     procedure Set_HideSelection(Value: WordBool); safecall;
  92.     procedure Set_HotTrack(Value: WordBool); safecall;
  93.     procedure Set_MultiSelect(Value: WordBool); safecall;
  94.     procedure Set_OwnerData(Value: WordBool); safecall;
  95.     procedure Set_OwnerDraw(Value: WordBool); safecall;
  96.     procedure Set_ParentColor(Value: WordBool); safecall;
  97.     procedure Set_ParentFont(Value: WordBool); safecall;
  98.     procedure Set_ReadOnly(Value: WordBool); safecall;
  99.     procedure Set_RowSelect(Value: WordBool); safecall;
  100.     procedure Set_ShowColumnHeaders(Value: WordBool); safecall;
  101.     procedure Set_SortType(Value: TxSortType); safecall;
  102.     procedure Set_ViewStyle(Value: TxViewStyle); safecall;
  103.     procedure Set_Visible(Value: WordBool); safecall;
  104.     procedure UpdateItems(FirstIndex, LastIndex: Integer); safecall;
  105.     function Get_Items: IListItems; safecall;
  106.   end;
  107.  
  108. implementation
  109.  
  110. uses ComObj, About;
  111.  
  112. { TListViewX }
  113.  
  114. procedure TListViewX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  115. begin
  116.   { Define property pages here.  Property pages are defined by calling
  117.     DefinePropertyPage with the class id of the page.  For example,
  118.       DefinePropertyPage(Class_ListViewXPage); }
  119. end;
  120.  
  121. procedure TListViewX.EventSinkChanged(const EventSink: IUnknown);
  122. begin
  123.   FEvents := EventSink as IListViewXEvents;
  124. end;
  125.  
  126. procedure TListViewX.InitializeControl;
  127. begin
  128.   FDelphiControl := Control as TListView2;
  129.   FDelphiControl.OnClick := ClickEvent;
  130.   FDelphiControl.OnDataHint := DataHintEvent;
  131.   FDelphiControl.OnDblClick := DblClickEvent;
  132.   FDelphiControl.OnKeyPress := KeyPressEvent;
  133.   FDelphiControl.OnResize := ResizeEvent;
  134.   FItems := LVItems.TListItems.Create(FDelphiControl.Items);
  135. end;
  136.  
  137. function TListViewX.AlphaSort: WordBool;
  138. begin
  139.   Result := FDelphiControl.AlphaSort;
  140. end;
  141.  
  142. function TListViewX.ClassNameIs(const Name: WideString): WordBool;
  143. begin
  144.   Result := FDelphiControl.ClassNameIs(Name);
  145. end;
  146.  
  147. function TListViewX.DrawTextBiDiModeFlags(Flags: Integer): Integer;
  148. begin
  149.   Result := FDelphiControl.DrawTextBiDiModeFlags(Flags);
  150. end;
  151.  
  152. function TListViewX.DrawTextBiDiModeFlagsReadingOnly: Integer;
  153. begin
  154.   Result := FDelphiControl.DrawTextBiDiModeFlagsReadingOnly;
  155. end;
  156.  
  157. function TListViewX.Get_AllocBy: Integer;
  158. begin
  159.   Result := FDelphiControl.AllocBy;
  160. end;
  161.  
  162. function TListViewX.Get_BiDiMode: TxBiDiMode;
  163. begin
  164.   Result := Ord(FDelphiControl.BiDiMode);
  165. end;
  166.  
  167. function TListViewX.Get_BorderStyle: TxBorderStyle;
  168. begin
  169.   Result := Ord(FDelphiControl.BorderStyle);
  170. end;
  171.  
  172. function TListViewX.Get_Checkboxes: WordBool;
  173. begin
  174.   Result := FDelphiControl.Checkboxes;
  175. end;
  176.  
  177. function TListViewX.Get_Color: OLE_COLOR;
  178. begin
  179.   Result := OLE_COLOR(FDelphiControl.Color);
  180. end;
  181.  
  182. function TListViewX.Get_ColumnClick: WordBool;
  183. begin
  184.   Result := FDelphiControl.ColumnClick;
  185. end;
  186.  
  187. function TListViewX.Get_Ctl3D: WordBool;
  188. begin
  189.   Result := FDelphiControl.Ctl3D;
  190. end;
  191.  
  192. function TListViewX.Get_Cursor: Smallint;
  193. begin
  194.   Result := Smallint(FDelphiControl.Cursor);
  195. end;
  196.  
  197. function TListViewX.Get_DoubleBuffered: WordBool;
  198. begin
  199.   Result := FDelphiControl.DoubleBuffered;
  200. end;
  201.  
  202. function TListViewX.Get_DragCursor: Smallint;
  203. begin
  204.   Result := Smallint(FDelphiControl.DragCursor);
  205. end;
  206.  
  207. function TListViewX.Get_DragMode: TxDragMode;
  208. begin
  209.   Result := Ord(FDelphiControl.DragMode);
  210. end;
  211.  
  212. function TListViewX.Get_Enabled: WordBool;
  213. begin
  214.   Result := FDelphiControl.Enabled;
  215. end;
  216.  
  217. function TListViewX.Get_FlatScrollBars: WordBool;
  218. begin
  219.   Result := FDelphiControl.FlatScrollBars;
  220. end;
  221.  
  222. function TListViewX.Get_Font: IFontDisp;
  223. begin
  224.   GetOleFont(FDelphiControl.Font, Result);
  225. end;
  226.  
  227. function TListViewX.Get_FullDrag: WordBool;
  228. begin
  229.   Result := FDelphiControl.FullDrag;
  230. end;
  231.  
  232. function TListViewX.Get_GridLines: WordBool;
  233. begin
  234.   Result := FDelphiControl.GridLines;
  235. end;
  236.  
  237. function TListViewX.Get_HideSelection: WordBool;
  238. begin
  239.   Result := FDelphiControl.HideSelection;
  240. end;
  241.  
  242. function TListViewX.Get_HotTrack: WordBool;
  243. begin
  244.   Result := FDelphiControl.HotTrack;
  245. end;
  246.  
  247. function TListViewX.Get_MultiSelect: WordBool;
  248. begin
  249.   Result := FDelphiControl.MultiSelect;
  250. end;
  251.  
  252. function TListViewX.Get_OwnerData: WordBool;
  253. begin
  254.   Result := FDelphiControl.OwnerData;
  255. end;
  256.  
  257. function TListViewX.Get_OwnerDraw: WordBool;
  258. begin
  259.   Result := FDelphiControl.OwnerDraw;
  260. end;
  261.  
  262. function TListViewX.Get_ParentColor: WordBool;
  263. begin
  264.   Result := FDelphiControl.ParentColor;
  265. end;
  266.  
  267. function TListViewX.Get_ParentFont: WordBool;
  268. begin
  269.   Result := FDelphiControl.ParentFont;
  270. end;
  271.  
  272. function TListViewX.Get_ReadOnly: WordBool;
  273. begin
  274.   Result := FDelphiControl.ReadOnly;
  275. end;
  276.  
  277. function TListViewX.Get_RowSelect: WordBool;
  278. begin
  279.   Result := FDelphiControl.RowSelect;
  280. end;
  281.  
  282. function TListViewX.Get_SelCount: Integer;
  283. begin
  284.   Result := FDelphiControl.SelCount;
  285. end;
  286.  
  287. function TListViewX.Get_ShowColumnHeaders: WordBool;
  288. begin
  289.   Result := FDelphiControl.ShowColumnHeaders;
  290. end;
  291.  
  292. function TListViewX.Get_SortType: TxSortType;
  293. begin
  294.   Result := Ord(FDelphiControl.SortType);
  295. end;
  296.  
  297. function TListViewX.Get_ViewStyle: TxViewStyle;
  298. begin
  299.   Result := Ord(FDelphiControl.ViewStyle);
  300. end;
  301.  
  302. function TListViewX.Get_Visible: WordBool;
  303. begin
  304.   Result := FDelphiControl.Visible;
  305. end;
  306.  
  307. function TListViewX.Get_VisibleRowCount: Integer;
  308. begin
  309.   Result := FDelphiControl.VisibleRowCount;
  310. end;
  311.  
  312. function TListViewX.GetControlsAlignment: TxAlignment;
  313. begin
  314.  Result := TxAlignment(FDelphiControl.GetControlsAlignment);
  315. end;
  316.  
  317. function TListViewX.GetSearchString: WideString;
  318. begin
  319.   Result := FDelphiControl.GetSearchString;
  320. end;
  321.  
  322. function TListViewX.IsEditing: WordBool;
  323. begin
  324.   Result := FDelphiControl.IsEditing;
  325. end;
  326.  
  327. function TListViewX.IsRightToLeft: WordBool;
  328. begin
  329.   Result := FDelphiControl.IsRightToLeft;
  330. end;
  331.  
  332. function TListViewX.StringWidth(const S: WideString): Integer;
  333. begin
  334.   Result := FDelphiControl.StringWidth(S);
  335. end;
  336.  
  337. function TListViewX.UseRightToLeftAlignment: WordBool;
  338. begin
  339.   Result := FDelphiControl.UseRightToLeftAlignment;
  340. end;
  341.  
  342. function TListViewX.UseRightToLeftReading: WordBool;
  343. begin
  344.   Result := FDelphiControl.UseRightToLeftReading;
  345. end;
  346.  
  347. function TListViewX.UseRightToLeftScrollBar: WordBool;
  348. begin
  349.   Result := FDelphiControl.UseRightToLeftScrollBar;
  350. end;
  351.  
  352. procedure TListViewX._Set_Font(const Value: IFontDisp);
  353. begin
  354.   SetOleFont(FDelphiControl.Font, Value);
  355. end;
  356.  
  357. procedure TListViewX.AboutBox;
  358. begin
  359.   ShowListViewXAbout;
  360. end;
  361.  
  362. procedure TListViewX.Arrange(Code: TxListArrangement);
  363. begin
  364.   FDelphiControl.Arrange(TListArrangement(Code));
  365. end;
  366.  
  367. procedure TListViewX.FlipChildren(AllLevels: WordBool);
  368. begin
  369.   FDelphiControl.FlipChildren(AllLevels);
  370. end;
  371.  
  372. procedure TListViewX.InitiateAction;
  373. begin
  374.   FDelphiControl.InitiateAction;
  375. end;
  376.  
  377. procedure TListViewX.Scroll(DX, DY: Integer);
  378. begin
  379.   FDelphiControl.Scroll(DX, DY);
  380. end;
  381.  
  382. procedure TListViewX.Set_AllocBy(Value: Integer);
  383. begin
  384.   FDelphiControl.AllocBy := Value;
  385. end;
  386.  
  387. procedure TListViewX.Set_BiDiMode(Value: TxBiDiMode);
  388. begin
  389.   FDelphiControl.BiDiMode := TBiDiMode(Value);
  390. end;
  391.  
  392. procedure TListViewX.Set_BorderStyle(Value: TxBorderStyle);
  393. begin
  394.   FDelphiControl.BorderStyle := TBorderStyle(Value);
  395. end;
  396.  
  397. procedure TListViewX.Set_Checkboxes(Value: WordBool);
  398. begin
  399.   FDelphiControl.Checkboxes := Value;
  400. end;
  401.  
  402. procedure TListViewX.Set_Color(Value: OLE_COLOR);
  403. begin
  404.   FDelphiControl.Color := TColor(Value);
  405. end;
  406.  
  407. procedure TListViewX.Set_ColumnClick(Value: WordBool);
  408. begin
  409.   FDelphiControl.ColumnClick := Value;
  410. end;
  411.  
  412. procedure TListViewX.Set_Ctl3D(Value: WordBool);
  413. begin
  414.   FDelphiControl.Ctl3D := Value;
  415. end;
  416.  
  417. procedure TListViewX.Set_Cursor(Value: Smallint);
  418. begin
  419.   FDelphiControl.Cursor := TCursor(Value);
  420. end;
  421.  
  422. procedure TListViewX.Set_DoubleBuffered(Value: WordBool);
  423. begin
  424.   FDelphiControl.DoubleBuffered := Value;
  425. end;
  426.  
  427. procedure TListViewX.Set_DragCursor(Value: Smallint);
  428. begin
  429.   FDelphiControl.DragCursor := TCursor(Value);
  430. end;
  431.  
  432. procedure TListViewX.Set_DragMode(Value: TxDragMode);
  433. begin
  434.   FDelphiControl.DragMode := TDragMode(Value);
  435. end;
  436.  
  437. procedure TListViewX.Set_Enabled(Value: WordBool);
  438. begin
  439.   FDelphiControl.Enabled := Value;
  440. end;
  441.  
  442. procedure TListViewX.Set_FlatScrollBars(Value: WordBool);
  443. begin
  444.   FDelphiControl.FlatScrollBars := Value;
  445. end;
  446.  
  447. procedure TListViewX.Set_Font(var Value: IFontDisp);
  448. begin
  449.   SetOleFont(FDelphiControl.Font, Value);
  450. end;
  451.  
  452. procedure TListViewX.Set_FullDrag(Value: WordBool);
  453. begin
  454.   FDelphiControl.FullDrag := Value;
  455. end;
  456.  
  457. procedure TListViewX.Set_GridLines(Value: WordBool);
  458. begin
  459.   FDelphiControl.GridLines := Value;
  460. end;
  461.  
  462. procedure TListViewX.Set_HideSelection(Value: WordBool);
  463. begin
  464.   FDelphiControl.HideSelection := Value;
  465. end;
  466.  
  467. procedure TListViewX.Set_HotTrack(Value: WordBool);
  468. begin
  469.   FDelphiControl.HotTrack := Value;
  470. end;
  471.  
  472. procedure TListViewX.Set_MultiSelect(Value: WordBool);
  473. begin
  474.   FDelphiControl.MultiSelect := Value;
  475. end;
  476.  
  477. procedure TListViewX.Set_OwnerData(Value: WordBool);
  478. begin
  479.   FDelphiControl.OwnerData := Value;
  480. end;
  481.  
  482. procedure TListViewX.Set_OwnerDraw(Value: WordBool);
  483. begin
  484.   FDelphiControl.OwnerDraw := Value;
  485. end;
  486.  
  487. procedure TListViewX.Set_ParentColor(Value: WordBool);
  488. begin
  489.   FDelphiControl.ParentColor := Value;
  490. end;
  491.  
  492. procedure TListViewX.Set_ParentFont(Value: WordBool);
  493. begin
  494.   FDelphiControl.ParentFont := Value;
  495. end;
  496.  
  497. procedure TListViewX.Set_ReadOnly(Value: WordBool);
  498. begin
  499.   FDelphiControl.ReadOnly := Value;
  500. end;
  501.  
  502. procedure TListViewX.Set_RowSelect(Value: WordBool);
  503. begin
  504.   FDelphiControl.RowSelect := Value;
  505. end;
  506.  
  507. procedure TListViewX.Set_ShowColumnHeaders(Value: WordBool);
  508. begin
  509.   FDelphiControl.ShowColumnHeaders := Value;
  510. end;
  511.  
  512. procedure TListViewX.Set_SortType(Value: TxSortType);
  513. begin
  514.   FDelphiControl.SortType := TSortType(Value);
  515. end;
  516.  
  517. procedure TListViewX.Set_ViewStyle(Value: TxViewStyle);
  518. begin
  519.   FDelphiControl.ViewStyle := TViewStyle(Value);
  520. end;
  521.  
  522. procedure TListViewX.Set_Visible(Value: WordBool);
  523. begin
  524.   FDelphiControl.Visible := Value;
  525. end;
  526.  
  527. procedure TListViewX.UpdateItems(FirstIndex, LastIndex: Integer);
  528. begin
  529.   FDelphiControl.UpdateItems(FirstIndex, LastIndex);
  530. end;
  531.  
  532. procedure TListViewX.ClickEvent(Sender: TObject);
  533. begin
  534.   if FEvents <> nil then FEvents.OnClick;
  535. end;
  536.  
  537. procedure TListViewX.DataHintEvent(Sender: TObject; StartIndex,
  538.   EndIndex: Integer);
  539. begin
  540.   if FEvents <> nil then FEvents.OnDataHint(StartIndex, EndIndex);
  541. end;
  542.  
  543. procedure TListViewX.DblClickEvent(Sender: TObject);
  544. begin
  545.   if FEvents <> nil then FEvents.OnDblClick;
  546. end;
  547.  
  548. procedure TListViewX.KeyPressEvent(Sender: TObject; var Key: Char);
  549. var
  550.   TempKey: Smallint;
  551. begin
  552.   TempKey := Smallint(Key);
  553.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  554.   Key := Char(TempKey);
  555. end;
  556.  
  557. procedure TListViewX.ResizeEvent(Sender: TObject);
  558. begin
  559.   if FEvents <> nil then FEvents.OnResize;
  560. end;
  561.  
  562. function TListViewX.Get_Items: IListItems;
  563. begin
  564.   Result := FItems;
  565. end;
  566.  
  567. initialization
  568.   TActiveXControlFactory.Create(ComServer, TListViewX, TListView2,
  569.     Class_ListViewX, 1, '', 0, tmApartment);
  570. end.
  571.